package com.class05.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/servletB")
public class ServletB extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
//        1、向session中存入数据   ctrl + D
        session.setAttribute("name", "Tom");
//        2、向session中修改入数据
        session.setAttribute("name", "Jerry");
//        3、向session中删除数据
        session.removeAttribute("name");
        String servletInfo = getServletInfo();
        System.out.println("获取当前servlet信息为：" + servletInfo);
        ServletConfig config = getServletConfig();
        String servletName = config.getServletName();
        System.out.println("获取到当前的servlet名称：" + servletName);


    }
}
